package com.ruoyi.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.entity.TTaskExamPaper;
import com.ruoyi.exam.service.ITTaskExamPaperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 创建任务时绑定的试卷Controller
 * 
 * @author ruoyi
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/exam/task_exam_paper")
public class TTaskExamPaperController extends BaseController
{
    @Autowired
    private ITTaskExamPaperService tTaskExamPaperService;

    /**
     * 查询创建任务时绑定的试卷列表
     */
    @PreAuthorize("@ss.hasPermi('exam:task_exam_paper:list')")
    @GetMapping("/list")
    public TableDataInfo list(TTaskExamPaper tTaskExamPaper)
    {
        startPage();
        List<TTaskExamPaper> list = tTaskExamPaperService.selectTTaskExamPaperList(tTaskExamPaper);
        return getDataTable(list);
    }

    /**
     * 导出创建任务时绑定的试卷列表
     */
    @PreAuthorize("@ss.hasPermi('exam:task_exam_paper:export')")
    @Log(title = "创建任务时绑定的试卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTaskExamPaper tTaskExamPaper)
    {
        List<TTaskExamPaper> list = tTaskExamPaperService.selectTTaskExamPaperList(tTaskExamPaper);
        ExcelUtil<TTaskExamPaper> util = new ExcelUtil<TTaskExamPaper>(TTaskExamPaper.class);
        util.exportExcel(response, list, "创建任务时绑定的试卷数据");
    }

    /**
     * 获取创建任务时绑定的试卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:task_exam_paper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tTaskExamPaperService.selectTTaskExamPaperById(id));
    }

    /**
     * 新增创建任务时绑定的试卷
     */
    @PreAuthorize("@ss.hasPermi('exam:task_exam_paper:add')")
    @Log(title = "创建任务时绑定的试卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTaskExamPaper tTaskExamPaper)
    {
        return toAjax(tTaskExamPaperService.insertTTaskExamPaper(tTaskExamPaper));
    }

    /**
     * 修改创建任务时绑定的试卷
     */
    @PreAuthorize("@ss.hasPermi('exam:task_exam_paper:edit')")
    @Log(title = "创建任务时绑定的试卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTaskExamPaper tTaskExamPaper)
    {
        return toAjax(tTaskExamPaperService.updateTTaskExamPaper(tTaskExamPaper));
    }

    /**
     * 删除创建任务时绑定的试卷
     */
    @PreAuthorize("@ss.hasPermi('exam:task_exam_paper:remove')")
    @Log(title = "创建任务时绑定的试卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tTaskExamPaperService.deleteTTaskExamPaperByIds(ids));
    }
}
